package com.hzc.springchan.bean.response;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import java.util.HashMap;
import java.util.Map;

/**
 * Map数据返回体类
 * @author chen990627
 * @date 2022/10/06
 */
@Setter
@Getter
@ToString
public class MapDataResponse extends Response {

    private Map<String, Object> data;

    public static MapDataResponse newSuccess() {
        MapDataResponse response = new MapDataResponse();
        return (MapDataResponse) response.setSuccess();
    }

    public static MapDataResponse newSuccess(boolean dataInit) {
        MapDataResponse response = newSuccess();
        response.data = dataInit ? new HashMap<>() : null;
        return response;
    }

    public static MapDataResponse newSuccess(Map<String, Object> data) {
        Response response = MapDataResponse.newSuccess(false);
        ((MapDataResponse) response).setData(data);
        return (MapDataResponse) response;
    }

    public MapDataResponse put(String key, Object value) {
        this.data.put(key, value);
        return this;
    }

    public MapDataResponse remove(String key) {
        this.data.put(key, null);
        return this;
    }
}
